/*********************************************************************************
  *FileName:  fault_diagnosis.h
  *Version:   V1.0
  *Date:      2023-11-29
**********************************************************************************/

#ifndef  __fault_diagnosis_H__
#define  __fault_diagnosis_H__

/***************************************Includes***********************************/
#include "main.h"
#include "adc.h"
#include "bdc.h"

/***************************************Macros***********************************/
#define VOLTAGELOSSONLINE							300U				/* Voltage loss on diode about 0.3V*/
#define APPL_UNDER_VOLT_LEVEL						7500U				/** [1mV] */
#define APPL_OVER_VOLT_LEVEL						16500U				/** [1mV] */
#define APPL_UNDER_VOLT_RECOVER_LEVEL               8500U				/** [1mV] */
#define APPL_OVER_VOLT_RECOVER_LEVEL  	            17500U				/** [1mV] */
#define VOLTAGE_HYS 								300U				/** [mV] Voltage hysteresis */


#define OVER_TEMP_UNDER 						    -40					/** [C] */
#define OVER_TEMP_WARING 							135					/** [C] */
#define OVER_TEMP_ALARM 							150					/** [C] */
#define TEMPERATURE_HYS 							5					/** [C] Temperature hysteresis */


/***************************************Variables***********************************/



/***************************************Functions***********************************/
MotorStall_t MotorStallCheck_Calibration(uint16_t u16ActualPosition, uint16_t u16Current);
MotorStall_t MotorStallCheck(void);
ErrVoltage_t Under_OverVoltageCheck(uint16_t u16SupplyVoltage);
ErrTemp_t OverTemperatureCheck(int16_t i16Temperature);
void OverCurrent_Handle(void);

#endif
/* [] END OF fault_diagnosis.h */
